package cn.edu.neusoft.yuejian4.yuejian_4.fragment;

import android.content.Intent;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import cn.edu.neusoft.yuejian4.yuejian_4.R;
import cn.edu.neusoft.yuejian4.yuejian_4.pictureselectordemo.ReleaseNewActivity;
import cn.edu.neusoft.yuejian4.yuejian_4.adapter.ShowListAdapter;
import cn.edu.neusoft.yuejian4.yuejian_4.javaBean.Slideshow;
import cn.edu.neusoft.yuejian4.yuejian_4.listener.List_TListener;
import cn.edu.neusoft.yuejian4.yuejian_4.model.ShowModel;

/**
 * Created by Lix on 2018/10/9.
 */

public class ShowFragment extends Fragment implements View.OnClickListener {

    private View view;
    private ImageView show_user_img,show_img,fabu_btn,delete_img;
    private TextView show_user_name,show_time,show_intro;
    private RecyclerView recyclerView;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_show,container,false);
        initViews();
        initEvent();
        ShowModel showModel = new ShowModel();
        showModel.allShow(allshowlistener);
        return view;
    }

    List_TListener<Slideshow> allshowlistener = new List_TListener<Slideshow>() {
        @Override
        public void onResponse(List<Slideshow> list) {
            ShowListAdapter showListAdapter =new ShowListAdapter(getContext(),list);
            recyclerView.setAdapter(showListAdapter);
        }

        @Override
        public void onFail(String msg) {

        }
    };

    private void initViews(){
        recyclerView = (RecyclerView)view.findViewById(R.id.rv_show);
        LinearLayoutManager layoutManager = new LinearLayoutManager(this.getActivity());
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(layoutManager);
        show_user_img = (ImageView) view.findViewById(R.id.show_user_img);
        show_img = (ImageView) view.findViewById(R.id.show_img);
        show_user_name = (TextView)view.findViewById(R.id.show_user_name);
        show_time = (TextView)view.findViewById(R.id.show_time);
        show_intro = (TextView)view.findViewById(R.id.show_intro);
        fabu_btn = (ImageView)view.findViewById(R.id.show_fabu);

    }
    private void initEvent(){
      fabu_btn.setOnClickListener(this);
    }


    @Override
    public void onClick(View v) {
       switch (v.getId()){
           case R.id.show_fabu:
               Intent intent = new Intent(getActivity(), ReleaseNewActivity.class);
               startActivity(intent);
               break;
       }
    }
}
